package com.learning.javaweb_servlet_jdbc;

import java.sql.*;

public class JDBC_Teacher_Retrieve {
    //设置基础数据，链接数据库
    static final String URL = "jdbc:mysql://localhost:3306/jdbc_demo?useSSL=false&serverTimezone=GMT&characterEncoding=UTF-8";
    static final String USER = "root";
    static final String PASSWORD = "WQ9ABCAT";

    //查询语句
    static final String SQL = "SELECT * FROM teacher WHERE id > ?";


    public static void main(String[] args) {
        // 加载mysql驱动
        try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
             // 创建Statement对象
             PreparedStatement ps = conn.prepareStatement(SQL);
        ) {
            // 设置参数
            ps.setInt(1, 1);
            // 执行查询
            try (ResultSet rs = ps.executeQuery()) {
                // 输出查询结果
                while (rs.next()) {
                    System.out.println(rs.getObject(1) + " " + rs.getObject(2)+" " + rs.getObject(3));
                }
            }catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
